﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;
using SyringeControl.WinForms;

namespace SyringeControl
{
    /// <summary>
    /// An implementation of <see cref="IViewControlModel"/>
    /// </summary>
    class ViewControlModel : IViewControlModel
    {
        public ViewControlModel()
        {
            _types.Changed += InvokePropertyChanged;
            _control.Changed += InvokePropertyChanged;
            _selectedAssembly.Changed += InvokePropertyChanged;
            _selectedType.Changed += InvokePropertyChanged;
        }

        #region Члены INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
        void InvokePropertyChanged(string propName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propName));
        }

        #region Члены IViewControlModel

        ListProperty<Type> _types = new ListProperty<Type>("Types");
        public IList<Type> Types
        {
            get
            {
                return _types.Get();
            }
            set
            {
                _types.Set(value);
            }
        }

        SimpleProperty<Type> _selectedType = new SimpleProperty<Type>("SelectedType");
        public Type SelectedType
        {
            get
            {
                return _selectedType.Get();
            }
            set
            {
                _selectedType.Set(value);
            }
        }

        SimpleProperty<Assembly> _selectedAssembly = new SimpleProperty<Assembly>("SelectedAssembly");
        public Assembly SelectedAssembly
        {
            get
            {
                return _selectedAssembly.Get();
            }
            set
            {
                _selectedAssembly.Set(value);
            }
        }

        SimpleProperty<Control> _control = new SimpleProperty<Control>("TestedControl");
        public Control TestedControl
        {
            get { return _control.Get(); }
            set
            {
                _control.Set(value);
            }
        }
        #endregion
    }
}
